import config from "@/config"

const code=0
const timeout = 1000

// Mock.setup({
//   timeout: 100, // 设置延迟响应，模拟向后端请求数据
// });

// 文章列表
Mock.mock('/news/index', 'get', record.produceNewsData(30));
// 文章详情
Mock.mock(`${config.API_URL}/token`, 'post', user);

const roleList = 
    {  
        code:200,
        data:{token:"SCUI.Administrator.Auth",
        userInfo:{userId:"1",userName:"Administrator",dashboard:"0",
        role:["SA","admin","Auditor"]}},
        message:""
    }

const userlist = [
    {  
        password:"21232f297a57a5a743894a0e4a801fc3",
        username:"admin"
    },
    {  
        password:"21232f297a57a5a743894a0e4a801fc3",
        username:"user"
    }
]

const mock =[{
    url:'/api/token',
    method:'post',
    timeout,
    response: ({ body }) => {
        const data = body
        let hasUser = false
        for (const user of List) {
          if (user.username === data.username && user.password === data.password) {
            hasUser = true
            return {
              data: {
                code: code,
                data: roleList
              }
            }
          }
        }
        if (!hasUser) {
          return {
            data: {
              code: 500,
              message: '账号或密码错误'
            }
          }
        }
      }
},
]

export default mock
